//
//  TourisDestinationViewModel.swift
//  AirTravel
//
//  Created by apple on 2021/7/23.
//

import UIKit

protocol TourisDestinationDelegate:NSObjectProtocol {
    func tourisDestinationClick(data:NSDictionary)
}

class TourisDestinationViewModel: NSObject {
    var collView : UICollectionView?
    weak var delegate: TourisDestinationDelegate?
    var dataSouce : Array<Any>?
    let identifyD = "DestinationColl"
    
    
    func bindViewToViewModel(collView : UICollectionView) {
        self.collView = collView
        self.collView?.dataSource = self
        self.collView?.delegate = self
//        self.collView?.backgroundColor = UIColor.groupTableViewBackground
        let layout = UICollectionViewFlowLayout.init()
        layout.scrollDirection = .horizontal
        
        layout.itemSize = .init(width: (SCREEN_WIDTH - 50) / 3, height: (SCREEN_WIDTH - 50) / 3 + 35)
        layout.minimumInteritemSpacing = 8
        layout.minimumLineSpacing = 10
        layout.sectionInset = UIEdgeInsets.init(top: 10, left: 17, bottom: 10, right: 17)
        self.collView?.isScrollEnabled = false
        self.collView?.collectionViewLayout = layout
        self.collView?.showsVerticalScrollIndicator = true
        
        self.collView?.register(UINib.init(nibName: "DestinationColl", bundle: nil), forCellWithReuseIdentifier: identifyD)
    }
}


extension TourisDestinationViewModel:UICollectionViewDataSource,UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return  3
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell : DestinationColl = collectionView.dequeueReusableCell(withReuseIdentifier: identifyD, for: indexPath) as! DestinationColl

        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        if let array = self.dataSouce {
//            let dic = array[indexPath.row] as! NSDictionary
//            delegate?.guessLikeClick(data: dic as NSDictionary)
        }
    }
    
    
}
